package com.cls.business.controller;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.cls.business.entity.MemberInfo;
import com.cls.common.annotation.ControllerEndpoint;
import com.cls.common.enums.DictEnum;
import com.cls.common.utils.MyUtil;
import com.cls.common.entity.MyConstant;
import com.cls.common.controller.BaseController;
import com.cls.common.entity.QueryRequest;
import com.cls.common.entity.ResponseVO;
import com.github.pagehelper.PageInfo;
import com.cls.business.entity.EntrustCheckLog;
import com.cls.business.service.IEntrustCheckLogService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 委托课题审核记录表 Controller
 *
 * @author slx
 * @date 2020-12-04 15:46:13
 */
@Slf4j
@Validated
@Controller
@RequiredArgsConstructor
public class EntrustCheckLogController extends BaseController {

    private final IEntrustCheckLogService entrustCheckLogService;

    /**
    * 委托课题审核记录表列表页面
    **/
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/entrustCheckLog")
    public String entrustCheckLogIndex(){
        return MyUtil.view("business/entrustCheckLog/entrustCheckLog");
    }

    /**
    * 委托课题审核记录表新增页面
    * @return
    */
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/entrustCheckLog/entrustCheckLogAdd")
    public String entrustCheckLogAdd(Model model){
        return MyUtil.view("business/entrustCheckLog/entrustCheckLogAdd");
    }

    /**
    * 委托课题审核记录表修改页面
    * @return
    */
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/entrustCheckLog/entrustCheckLogUpdate/{entrustCheckLogId}")
    public String entrustCheckLogUpdate(@PathVariable Long entrustCheckLogId, Model model){
        EntrustCheckLog entrustCheckLog = entrustCheckLogService.getById(entrustCheckLogId);
        model.addAttribute("entrustCheckLog",entrustCheckLog);
        return MyUtil.view("business/entrustCheckLog/entrustCheckLogUpdate");
    }

    @GetMapping("{declareId}/entrustCheckLog/list")
    @ResponseBody
    public ResponseVO memberInfoList(QueryRequest request, @PathVariable long declareId) {
        EntrustCheckLog entrustCheckLog = new EntrustCheckLog();
        entrustCheckLog.setDeclareId(declareId);
        PageInfo<EntrustCheckLog> pageInfo =  this.entrustCheckLogService.findEntrustCheckLogs(request, entrustCheckLog);
        return ResponseVO.success(pageInfo);
    }

    /**
    * 委托课题审核记录表详情页面
    * @return
    */
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/entrustCheckLog/entrustCheckLogDetail/{entrustCheckLogId}")
    public String entrustCheckLogDetail(@PathVariable Long entrustCheckLogId, Model model){
        EntrustCheckLog entrustCheckLog = entrustCheckLogService.getById(entrustCheckLogId);
        model.addAttribute("entrustCheckLog",entrustCheckLog);
        return MyUtil.view("business/entrustCheckLog/entrustCheckLogDetail");
    }

    @GetMapping("entrustCheckLog")
    @ResponseBody
    @RequiresPermissions("entrustCheckLog:list")
    public ResponseVO getAllEntrustCheckLogs(EntrustCheckLog entrustCheckLog) {
        return ResponseVO.success(entrustCheckLogService.findEntrustCheckLogs(entrustCheckLog));
    }

    @GetMapping("entrustCheckLog/list")
    @ResponseBody
/*    @RequiresPermissions("entrustCheckLog:list")*/
    public ResponseVO entrustCheckLogList(QueryRequest request, EntrustCheckLog entrustCheckLog) {
        PageInfo<EntrustCheckLog> pageInfo =  this.entrustCheckLogService.findEntrustCheckLogs(request, entrustCheckLog);
        return ResponseVO.success(pageInfo);
    }

    @GetMapping("entrustCheckLog/applyList")
    @ResponseBody
    /*    @RequiresPermissions("entrustCheckLog:list")*/
    public ResponseVO applyList(QueryRequest request, EntrustCheckLog entrustCheckLog) {
        entrustCheckLog.setCheckType(DictEnum.CONCLUDE_APPLY.getCode());
        PageInfo<EntrustCheckLog> pageInfo =  this.entrustCheckLogService.findEntrustCheckLogs(request, entrustCheckLog);
        return ResponseVO.success(pageInfo);
    }

    @ControllerEndpoint(operation = "新增EntrustCheckLog", exceptionMessage = "新增EntrustCheckLog失败")
    @PostMapping("entrustCheckLog")
    @ResponseBody
    @RequiresPermissions("entrustCheckLog:add")
    public ResponseVO addEntrustCheckLog(@Valid EntrustCheckLog entrustCheckLog) {
        this.entrustCheckLogService.createEntrustCheckLog(entrustCheckLog);
        return ResponseVO.success();
    }

    @ControllerEndpoint(operation = "多个删除EntrustCheckLog", exceptionMessage = "删除EntrustCheckLog失败")
    @PostMapping("entrustCheckLog/deletes/{ids}")
    @ResponseBody
    @RequiresPermissions("entrustCheckLog:delete")
    public ResponseVO deleteEntrustCheckLogs(@PathVariable String ids) {
        String[] idArry = ids.split(StringPool.COMMA);
        this.entrustCheckLogService.deleteEntrustCheckLogs(idArry);
        return ResponseVO.success();
    }


    @ControllerEndpoint(operation = "删除单个EntrustCheckLog", exceptionMessage = "删除EntrustCheckLog失败")
    @PostMapping("entrustCheckLog/delete/{entrustCheckLogId}")
    @ResponseBody
    @RequiresPermissions("entrustCheckLog:delete")
    public ResponseVO deleteEntrustCheckLog(@PathVariable Long entrustCheckLogId) {
        this.entrustCheckLogService.removeById(entrustCheckLogId);
        return ResponseVO.success();
    }

    @ControllerEndpoint(operation = "修改EntrustCheckLog", exceptionMessage = "修改EntrustCheckLog失败")
    @PostMapping("entrustCheckLog/update")
    @ResponseBody
    @RequiresPermissions("entrustCheckLog:update")
    public ResponseVO updateEntrustCheckLog(EntrustCheckLog entrustCheckLog) {
        this.entrustCheckLogService.updateEntrustCheckLog(entrustCheckLog);
        return ResponseVO.success();
    }

    @ControllerEndpoint(operation = "修改EntrustCheckLog", exceptionMessage = "导出Excel失败")
    @PostMapping("entrustCheckLog/excel")
    @ResponseBody
    @RequiresPermissions("entrustCheckLog:export")
    public void export(QueryRequest queryRequest, EntrustCheckLog entrustCheckLog, HttpServletResponse response) {
        List<EntrustCheckLog> entrustCheckLogs = this.entrustCheckLogService.findEntrustCheckLogs(queryRequest, entrustCheckLog).getList();
        ExcelKit.$Export(EntrustCheckLog.class, response).downXlsx(entrustCheckLogs, false);
    }
}
